﻿using RedisClientCluster;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace RedisTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        string host = "";
        private void button1_Click(object sender, EventArgs e)
        {
            host = RedisNodesInit.GetRedisNode(textBox1.Text);
            SERedisHelper._conn = host ;
            string result = SERedisHelper.StringGet(textBox1.Text);
            if (result == null)
            {
                //int index = RedisNodesInit.nodes.FindIndex(x => x == host);
                //if (index < RedisNodesInit.nodes.Count)
                //{
                //    host = RedisNodesInit.nodes[index + 1];
                //}
                //else
                //{
                //    host = RedisNodesInit.nodes[0];
                //}
                host = RedisNodesInit.GetRedisNode_Bak(textBox1.Text);
                SERedisHelper._conn = host;
                result = SERedisHelper.StringGet(textBox1.Text);
            }
            textBox2.Text = result;
        }

        private void button2_Click(object sender, EventArgs e)
        {
            host = RedisNodesInit.GetRedisNode(textBox1.Text);
            SERedisHelper._conn = host ;
            bool result = SERedisHelper.StringSet(textBox1.Text, textBox2.Text);
            if (result)
            {
                //int index = RedisNodesInit.nodes.FindIndex(x => x == host);
                //if (index < RedisNodesInit.nodes.Count-1)
                //{
                //    host = RedisNodesInit.nodes[index + 1];
                //}
                //else
                //{
                //    host = RedisNodesInit.nodes[0];
                //}
                host = RedisNodesInit.GetRedisNode_Bak(textBox1.Text);
                SERedisHelper._conn = host;
                result = SERedisHelper.StringSet(textBox1.Text, textBox2.Text);
            }
            textBox2.Text = result.ToString() ;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            var result = HashAlgorithmTest.Test();
            textBox2.Text = result;
        }
    }
}
